// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InstrumentStaticDataEquityVanillaOption.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;
    using System.ComponentModel;

    using Org.OpenTrader.Framework.DataModel;
    using Org.OpenTrader.Framework.Forge.Attributes;
    using Org.OpenTrader.Framework.Forge.DataCache;
    using Org.OpenTrader.Framework.Forge.Enums;
    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The instrument equity vanilla option.
    /// </summary>
    [Serializable]
    [InstrumentFriendlyDisplay("Equity Vanilla Option", "Vanilla Option written on Equity")]
    public sealed class InstrumentStaticDataEquityVanillaOption : InstrumentStaticData, 
                                                                  IInstrumentStaticDataEquityVanillaOption
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="InstrumentStaticDataEquityVanillaOption"/> class. 
        /// Initializes a new instance of the <see cref="InstrumentEquityVanillaOption"/> class.
        /// </summary>
        /// <param name="dictionaryID">
        /// The dictionary ID.
        /// </param>
        /// <param name="dbInstrumentEquityVanillaOption">
        /// The dbInstrumentEquityVanillaOption.
        /// </param>
        /// <param name="dbInstrument">
        /// The dbInstrument.
        /// </param>
        public InstrumentStaticDataEquityVanillaOption(
            Guid dictionaryID, 
            DBInstrumentStaticDataEquityVanillaOption dbInstrumentEquityVanillaOption, 
            DBInstrumentStaticData dbInstrument)
            : base(dictionaryID, dbInstrument)
        {
            this.Sector = EnumDecoder<ESector>.Parse(dbInstrumentEquityVanillaOption.Sector);

            if (dbInstrumentEquityVanillaOption.T != null)
            {
                this.T = (DateTime)dbInstrumentEquityVanillaOption.T;
            }

            if (dbInstrumentEquityVanillaOption.K != null)
            {
                this.K = (double)dbInstrumentEquityVanillaOption.K;
            }

            this.OptionType = EnumDecoder<EOptionType>.Parse(dbInstrumentEquityVanillaOption.OptionType);
            this.ExerciseType = EnumDecoder<EExerciseType>.Parse(dbInstrumentEquityVanillaOption.ExerciseType);
            this.Underlying =
                Singleton<DC>.Instance.GetInstrumentStaticDataFromCache<IInstrumentStaticDataEquity>(
                    dbInstrumentEquityVanillaOption.ID);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets ExerciseType.
        /// </summary>
        [Category("Equity Vanilla Option (Parameters)")]
        [Description("Type of exercise")]
        public EExerciseType ExerciseType { get; set; }

        /// <summary>
        /// Gets or sets K.
        /// </summary>
        [Category("Equity Vanilla Option (Parameters)")]
        [Description("Strike Price")]
        public double K { get; set; }

        /// <summary>
        /// Gets or sets OptionType.
        /// </summary>
        [Category("Equity Vanilla Option (Parameters)")]
        [Description("Type of option")]
        public EOptionType OptionType { get; set; }

        /// <summary>
        /// Gets or sets Sector.
        /// </summary>
        [Category("Equity Vanilla Option (Underlying)")]
        [Description("The Sector of the underlying Equity")]
        public ESector Sector { get; set; }

        /// <summary>
        /// Gets or sets T.
        /// </summary>
        [Category("Equity Vanilla Option (Parameters)")]
        [Description("Maturity")]
        public DateTime T { get; set; }

        /// <summary>
        /// Gets Type.
        /// </summary>
        public override string Type
        {
            get
            {
                return "EquityVanillaOption";
            }
        }

        /// <summary>
        /// Gets or sets Underlying.
        /// </summary>
        [Category("Equity Vanilla Option (Underlying)")]
        [Description("Underlying Equity")]
        [TypeConverter(typeof(string))]
        public IInstrumentStaticDataEquity Underlying { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The string representation.
        /// </summary>
        /// <returns>
        /// Returns "Equity Vanilla Option"
        /// </returns>
        public override string ToString()
        {
            return base.ToString() + " (Equity Vanilla Option)";
        }

        #endregion
    }
}